package com.shenmazong;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.Reader;
import java.io.StringReader;

public class JsonTest {

    public static void main(String[] args) {

        TbUser tbUser = new TbUser();
        tbUser.setId(1);
        tbUser.setName("唐伯虎");
        tbUser.setAge(99);

        ObjectMapper mapper = new ObjectMapper();

        try {
            String jsonString = mapper.writerWithDefaultPrettyPrinter()
                    .writeValueAsString(tbUser);
            System.out.println(jsonString);

            TbUser tbUser1 = mapper.readValue(jsonString, TbUser.class);
            System.out.println(tbUser1);

            //
            ObjectMapper objectMapper = new ObjectMapper();

            String carJson =
                    "{ \"brand\" : \"Mercedes\", \"doors\" : 4 }";
            Reader reader = new StringReader(carJson);

        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        //Person deserializedPerson = mapper.readValue(jsonString, Person.class);
    }
}
